<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="接口类型" name="serviceId" type="select" :data="api.gateway.list" label-key="routeTitle" value-key="serviceId"></f-search-form-item>
        <f-search-form-item label="接口名称" name="path"/>
        <f-search-form-item label="登录鉴权" name="isAuth" type="select" :data="api.common.authState"></f-search-form-item>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="apiId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.baseApi">
          <span slot="companyLogo" slot-scope="text, record, index">
          <img :src="record.companyLogo" v-viewer class="radius-img">
        </span>
        <span slot="isAuth" slot-scope="text, record, index">
          <a-switch v-model="record.isAuth==1" checkedChildren="是" unCheckedChildren="否" @change="(checked) => setAuthState(checked,record)"/>
        </span>
       <!-- <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider shopType="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon shopType="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.companyId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>-->
      </f-table>
    </a-card>
  </div>
</template>

<script>


  export default {
    name: 'TableList',
    components: {},
    data () {
      let me = this
      return {
        //列表初始化查询参数
        queryParam: {},
        companyType: [{ value: 'SUPPLIER', label: '供应商' }, { value: 'DEVELOPER', label: '开发商' }, { value: 'CONSTRUCTOR', label: '施工方' }, { value: 'DESIGNER', label: '设计方' }, { value: 'HOTEL', label: '酒店管理' }],
        // 表头
        columns: [

          {
            title: '接口名称',
            dataIndex: 'apiName'
          },
          {
            title: '路径',
            width: 100,
            dataIndex: 'path'
          },
          {
            title: '分类',
            dataIndex: 'apiCategory'
          },
          {
            title: 'serviceId',
            dataIndex: 'serviceId'
          },
          {
            title: '登陆鉴权',
            align: 'center',
            dataIndex: 'isAuth',
            scopedSlots: { customRender: 'isAuth' }
          },
          {
            title: '描述',
            dataIndex: 'apiDesc'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '180px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [

          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function (table) {
              table.remove()
            }
          }
        ]
      }
    },
    created () {

    },
    methods: {
      searchHandler(params) {
        this.$refs.table.refresh(true, params)
      },
      setAuthState (check, record) {
        this.http.post(this, {
          url: this.api.baseApi.setAuthState,
          data: {
            ids: record.apiId,
            isAuth: Number(check)
          },
          success (me, data) {
            record.isAuth = data
          }
        })
      }
    }
  }
</script>
